package com.hbx.controller;


import com.hbx.aspect.annotation.SensitiveFilter;
import com.hbx.model.PkResult;
import com.hbx.service.PkResultService;
import com.hbx.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hbx
 * @since 2022-01-29
 */
@RestController
@RequestMapping("/pkresult")
@Api(tags = "pk观点处理器")
public class PkResultController {
    @Autowired
    private PkResultService resultService;

    /**
     * 发表观点
     * @param result
     * @return
     */
    @RequestMapping(value = "/addPkResult",method = RequestMethod.POST)
    @ApiOperation("添加观点")
    @SensitiveFilter
    public Result addPkResult(@RequestBody PkResult result){
        Result r = new Result();
        if (result == null) {
            r.setCode(400).setMsg("入参错误");
            return r;
        }
        if (result.getResultType() == null) {
            r.setCode(400).setMsg("入参错误");
            return r;
        }
        if (result.getResultContent() == null || !StringUtils.hasLength(result.getResultContent())) {
            r.setCode(400).setMsg("入参错误");
            return r;
        }
        resultService.addPkResult(result, r);
        return r;
    }

    /**
     * 支持与取消支持
     * @param id
     * @return
     */
    @RequestMapping(value = "/addResultNiu",method = RequestMethod.GET)
    @ApiOperation("支持与取消支持")
    public Result addResultNiu(@RequestParam("id") Integer id){
        Result r = new Result();
        if (id == null) {
            r.setCode(400).setMsg("入参错误");
            return r;
        }

        resultService.addResultNiu(id, r);
        return r;
    }

    /**
     * 删除观点
     * @param id
     * @return
     */
    @RequestMapping(value = "/removeIdea",method = RequestMethod.GET)
    @ApiOperation("删除观点")
    public Result removeIdea(@RequestParam("id") Integer id){
        Result r = new Result();
        if (id == null) {
            r.setCode(400).setMsg("入参错误");
            return r;
        }

        resultService.removeIdea(id, r);
        return r;
    }
}

